package com.topvision.controller;

import com.topvision.common.response.SuccessResponse;
import com.topvision.common.security.UserInfo;
import com.topvision.common.security.UserInfoUtils;
import com.topvision.common.web.BaseController;
import com.topvision.domain.ArRecPro;
import com.topvision.service.ArRecProService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Ar识别属性控制类
 *
 * @author shengwm
 * @create 2018-04-28 9:35
 **/
@RestController
@RequestMapping("/arRecPro")
@Api(value = "识别属性控制类", description = "识别属性控制类")
@Slf4j
public class ArRecProController extends BaseController {
    @Autowired
    private ArRecProService arRecProService;

    @Autowired
    private UserInfoUtils userInfoUtils;

    @PostMapping("addRecPro")
    public ResponseEntity addRecPro(@RequestBody ArRecPro arRecPro) {
        arRecProService.save(arRecPro);
        return ResponseEntity.ok(SuccessResponse.of(arRecPro));
    }

    @PostMapping("editRecPro")
    public ResponseEntity editRecPro(@RequestBody ArRecPro arRecPro) {
        arRecProService.save(arRecPro);
        return ResponseEntity.ok(SuccessResponse.of(arRecPro));
    }

    @PostMapping("delRecPro")
    public ResponseEntity delRecPro(@RequestBody ArRecPro arRecPro) {
        arRecProService.del(arRecPro);
        return ResponseEntity.ok(SuccessResponse.of());
    }

    @GetMapping("/arRecPros/{arRecId}")
    public ResponseEntity facePros(@PathVariable String arRecId, Principal principal) {
        UserInfo userInfo = userInfoUtils.getUserInfo(principal);
        Map<String, Object> params = new HashMap<>();
        params.put("createdBy", userInfo.getName());
        params.put("arRecId", Long.valueOf(arRecId));
        List<ArRecPro> arRecPros = arRecProService.list(params);
        return ResponseEntity.ok(SuccessResponse.of(arRecPros));
    }

}
